
<?php
    include ('../login/authenticated.php');
    #include ('../upload/upload.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Web site</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="title" content="Web site" />
        <meta name="description" content="Site description here" />
        <meta name="keywords" content="keywords here" />
        <meta name="language" content="en" />
        <meta name="subject" content="Site subject here" />
        <meta name="robots" content="All" />
        <meta name="copyright" content="Your company" />
        <meta name="abstract" content="Site description here" />
        <meta name="MSSmartTagsPreventParsing" content="true" />
        
        <link id="theme" rel="stylesheet" type="text/css" href="../../css/style.css" title="theme" />
        <script type="text/javascript" language="javascript" src="../../js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="../../js/custom.js"></script>
        <script type="text/javascript" language="javascript" src="../../js/addon.js"></script>
    </head>
    <body> 

        <div id="wrapper"> 
            <div class="overlay"></div>  
            <div class="border-top"></div>  
            <div class="content"> 
                <div id="container"> 
                    <div class="hd"> 
                        <div id="container-top"> 
                            
                        </div>  
                        <div id="banner">
                           
                            <div id="suchfeld">
                                <form style="display:inline">

                                    <input type="text" name="firstname" /> suchen

                                </form>
                            </div> 
                            <div id="hmenu-wpr"> 
                                <ul id="hmenu" class="sf-menu sf-js-enabled sf-shadow">
                                    <li class="current" style="border:none"> 
                                        <a class="toplvl sf-with-ul" href="../../index.php">Home</a>
                                    </li>
                                    <li> 
                                        <a href="../upload/upload.php" class="toplvl">Ressource</a>  
                                        <ul>
                                            <li> 
                                                <a href="../download/download.php">Bachelor</a> 
                                            </li>
                                            <li class="current"> 
                                                <a href="../download/download.php">Master</a>  

                                            </li>
                                        </ul> 
                                    </li>

<!--                                    <li> 
                                        <a class="toplvl" href="#">Mein Profil</a>  
                                        <ul>
                                            <li> 
                                                <a href="#">Einstellungen</a> 
                                            </li>
                                             <li> 
                                                <a href="#">Profil bearbeiten</a> 
                                            </li>
                                             <li> 
                                                <a href="#">Freunde</a> 
                                            </li>

                                        </ul> 
                                    </li>  -->
                                    <li> 
                                        <a class="toplvl" href="#">News</a> 
                                        <ul>
                                            <li> 
                                                <a href="#">Aktuel</a> 
                                            </li>
                                            <li> 
                                                <a href="#">Archive</a> 
                                            </li>
                                        </ul>
                                    </li>
                                    <li> 
                                        <?php
              if(is_authenticated()) {
                  echo '<li> 
                          <a class="toplvl" href="module/login/logout.php">Logout</a>  
                       </li>';
              } else {
                  echo '<li> 
                          <a class="toplvl" href="login.php">Login</a>  
                       </li>';
              }
                                       
?>    
                                    </li>  
                                </ul> 
                            </div>  
                        </div>  

                        <div class="bd"> 
                            <div id="page"> 
                                <!-- SIDEBAR  -->  
                                <div id="sidebar"> 
                                    <div class="content"> 
                                        <div class="sidebox1"> 
                                            <h2>Side Box Menu</h2>  
                                            <div class="vmenu"> 
                                                <ul>
                                                    <li>
                                                        <a href="#">Category 1</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Category 2</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Category 3</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Category 4</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Category 5</a>
                                                    </li>
                                                </ul> 
                                            </div> 
                                        </div>  
                                        <div> 
                                            <img src="../images/business-man-1.png" style="width:100%" /> 
                                        </div>  
                                        <div class="sidebox1"> 
                                            <h2>Side Box Heading</h2>  
                                            <p></p> 
                                        </div> 
                                    </div> 
                                </div>  
                                <!-- END SIDEBAR  -->  
                                <!-- MAIN COLUMN -->  
                                <div id="main"> 
<!--                                    <div class="content">-->
<!--                                        <div id="login_hd">
                                            <h3></h3>  
                                             <p> 
                                               <img src="images/bizwoman-1.png" style="float:right;margin-left:20px" /> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.
                                             </p>    
                                             <h2 style="margin-top:35px;">Heading h2</h2>    
                                        </div>-->
<!--                                        <div id="conten">-->
 <?php

include_once ('/../../dao_class/Ressource.php');
include_once ('/../../dao_class/RessourceDao.php');
include_once ('/../../dao_class/Datasource.php');
include_once ('/../../dao_class/UserDao.php');
include_once ('/../../dao_class/User.php');

class Datei_upload {

   #Function to upload the new Datei
   static function ressourceAnlegen(){
        $fehler='';
        $content='';
        $server = 'localhost';
        $dbname = 'ai-vas';
        $user = 'root';
        $password = '';
        
            
        # Connection a la basse de donnée
       
       $conn = new Datasource($server, $dbname, $user, $password);
       $RessourceDao = new RessourceDao();
       $Ressource = $RessourceDao->createValueObject();
       #$UserDao = new UserDao();
       #$User = $UserDao->createValueObject();
       
        
//        @session_start();
//        
//        $_SESSION['id_user'] = $User->getId_user();
//       
       
       # verification si les champs sont remplient
       #if ($_SESSION['id_user']){
        if(isset($_POST['los']) ){
            
            #$Ressource->setId_user ($_SESSION['id_user']);
            
            if(isset($_POST['fach'])&& !is_array($_POST['fach']) && $_POST['fach'] != ''){
                $Ressource->setFach($_POST['fach']);
            } else {
                $fehler .= "Keinen Fach eingeben. <br>";
            }
            if(isset($_POST['professor'])&& !is_array($_POST['professor']) && $_POST['professor'] != ''){
                $Ressource->setProfessor($_POST['professor']);
            } else {
                $fehler .= "Keinen Professor eingeben. <br>";
            }
            if (isset ($_FILES['speicherOrt']))
            {   
                
                $Ressource->setName ($_FILES['speicherOrt']['name']); #Name der Datei
                $Ressource->setExtension ($_FILES['speicherOrt']['type']); #Type der Datei
                $Ressource->setGroesse($_FILES['speicherOrt']['size']); #Größe der Datei
                
                #definieren die Randomzahl, die bei der datei angehängt sollte
                $random_digit = rand(0000,9999);
                #neue name erzeugen
                $new_file_name = $random_digit.'.';//.$Ressource->setName($_FILES['speicherOrt']['type']);
                
                if (($_FILES['speicherOrt']['type']) == 'application/pdf'){ # prüft ob der Datei der richtige Type ist
                    if (($_FILES['speicherOrt']['size']) <= 512000){         #prüft ob der datei die richtigue grösse hat
                        
                        # prüft ob ein datei mit der gleichen namen schon vorhanden wenn ja ersetz mit einer Nummer
                        # wenn nein einfach speichern
                        
                        if(file_exists('../../ressource/'.basename($_FILES['speicherOrt']['name']))){
                            move_uploaded_file($_FILES['speicherOrt']['tmp_name'], '../../ressource/'
                            .($_FILES['speicherOrt']['name']). $new_file_name . basename($_FILES['speicherOrt']['type']));
                            $Ressource->setSpeicherOrt ('../../ressource/'.basename($_FILES['speicherOrt']['name']));
                            print ' Erfolreich Upgeload exists';
                        }else{
                         move_uploaded_file($_FILES['speicherOrt']['tmp_name'], '../../ressource/'.basename($_FILES['speicherOrt']['name']));
                         $Ressource->setSpeicherOrt ('../../ressource/'.basename($_FILES['speicherOrt']['name']));
                         print ' Erfolreich Upgeload not exit';
                        }
                    }else{
                        $fehler .= "Der Datei ist groß als 5 MB das geht nicht";
                        }
                }else {
                    $fehler .= "Der Datei muss ein pdf sein";
                    }
                
            } else {
                $fehler .= "Kein Ressource eingebenen oder ungültiges Format! <br>";
            }


        // introduction des informations concernant la Ressource dans la base de donnée

            if(!$fehler ){
                $RessourceDao->create($conn, $Ressource);
            } else {
                $content = "<p class='nachricht'>". $fehler . "</p><br>";
            }
   }

# Tableau pour introduire les informations de la ressource
   
        $content = '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']);
        $content = $content.'" method="post" enctype="multipart/form-data"><input type="hidden" name="id"';

        $content = $content. '<table align="center"cellpadding=2><tr align="center"> </tr>
            
         <tr align="center">
         <td><p class="nachricht"> Fach</td>
        <td><p class="nachricht">
        <select name="fach">
            <option></option>
            <option value="Mathematik">Mathematik</option>
            <option value="Programmierung1">Programmierung 1</option>
            <option value="Programmierung2">Programmierung 2</option>
            <option value="Datenbank1">Datenbank 1</option>
            <option value="Datenbank2">Datenbank 2</option>
        </select>
        </p>
        </td>
        </tr>
        <tr align="center">
            <td> <p class="nachricht"> Professor </td> <td><p class="nachricht">
            <input name="professor" type="text" style="font-family: Verdana;></td>
        </tr>
        <tr align="center">
            <td> <p class="nachricht"> Datei Hochladen: 
            <font color ="#A52A2A"> Bitte nur PDF hochladen </td> <td><p class="nachricht">
            <input name="speicherOrt" type="file" style="font-family: Verdana; font-size:8px" value="speicherOrt" ></td>
        </tr>
        <td><input name="los" value="Abschicken" type="submit" style="font-family: Verdana; font-size:10px"></td>
        <td>
        
    </table>
</form>';

return $content;

    }
   #}
    
}
       $content = Datei_upload::ressourceAnlegen();
        print $content;

?>

                                            </div>
                                         </div>
                                    </div> 
                                </div>  
                                <!-- END MAIN -->  
                                <!-- SIDEBAR 2  -->  
                                <div id="sidebar2"> 
                                    <div class="content"> 
                                        <div class="sidebox2"> 
                                            <h2>Sidebar Bloc</h2>  
                                            <div class="vmenu"> 
                                                <ul>
                                                    <li>
                                                        <a href="#">Lorem Ipsum</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Suspendisse</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Maecenas</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Sed non risus</a>
                                                    </li>
                                                    <li>
                                                        <a href="#">Consectetuer</a>
                                                    </li>
                                                </ul> 
                                            </div> 
                                        </div>  
                                        <div class="sidebox2"> 
                                            <h2></h2>  
                                            <p></p>  
                                            <div style="margin-top:20px"> 
<!--                                                <img src="images/cross-browser.png" style="width:100%" /> -->
                                            </div>  
                                            <p style="margin-top:20px"></p> 
                                        </div> 
                                    </div> 
                                </div>  
                                <!-- END SIDEBAR 2  -->  
                                <div class="clear" style="height:60px"></div> 
                            </div> 
                        </div>  
                        <div class="ft"> 
                            <div id="footer"> 
                                <div class="content"> 
                                    <p>
                                        <a href="http://www.dotemplate.com"></a> 
                                    </p> 
                                </div> 
                            </div>  
                            <div id="container-bottom"></div> 
                        </div> 
                    </div> 
            <div class="clear"></div> 
    </body>
</html>
